﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using ControleRepresentante.Logic;
using ControleRepresentante.Logic.Models;
using ControleRepresentante.Logic.Repositories;
using ControleRepresentante.Logic.Repositories.SearchExtensions;
using WebSite.Controllers.ControllerExtensions;
using WebSite.ViewModels.ViewModelExtensions.DetailsViewModelExtensions;
using WebSite.ViewModels.ViewModelExtensions.EditViewModelExtensions;
using WebSite.ViewModels.ViewModelExtensions.IndexViewModelExtensions;

namespace ControleRepresentante.UnitTests.Mocks
{
    public class MockControllerExtension : ControllerExtensionBase<MockModel>
    {
        public Dictionary<string, string> TryUpdateErrors { get; private set; }
        public MockModel LastSetModel { get; private set; }
        public MockModel LastTryUpdateModel { get; private set; }
        public FormCollection LastTryUpdateFormCollection { get; private set; }

        public MockControllerExtension()
        {
            TryUpdateErrors = new Dictionary<string, string>();
        }

        protected override IIndexViewModelExtension DoGetIndexViewModelExtension(FormCollection formCollection, IRepository repository)
        {
            return new MockIndexViewModelExtension(formCollection, repository);
        }

        public override IEditViewModelExtension EditViewModelExtension { get { return new MockEditViewModelExtension(); } }
        public override IDetailsViewModelExtension DetailsViewModelExtension { get { return new MockDetailsViewModelExtension(); } }

        public override ISearchExtension GetSearchExtension(FormCollection formCollection)
        {
            throw new NotImplementedException();
        }

        public override void RegisterIndexColumns(IIndexColumnsProvider indexColumnsProvider)
        {
        }

        protected override Dictionary<string, string> TryUpdateModel(MockModel model, FormCollection formCollection)
        {
            LastTryUpdateModel = model;
            LastTryUpdateFormCollection = formCollection;
            return TryUpdateErrors;
        }

        protected override Area Area { get { return MockController.AreaUsed; } }

        protected override void SetModel(MockModel model)
        {
            LastSetModel = model;
        }

        protected override bool CanHandle(Representante representante)
        {
            throw new NotImplementedException();
        }
    }
}